package com.sywb.chuangyebao.view.dialog;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;

import com.sywb.chuangyebao.R;
import com.sywb.chuangyebao.contract.InsertDialogContract;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 插屏dialog
 */
public class InsertAdvertisementDialog extends BaseDialogFragment<InsertDialogContract.InsertDialogPresenter> implements InsertDialogContract.InsertDialogView {
    @BindView(R.id.insert_close_iv)
    ImageView insertCloseIv;
    @BindView(R.id.insert_iv)
     ImageView insertIv;
    private AlertDialog.OnClickListener mClickListener;
    @Override
    public int getLayoutId(Bundle bundle) {
        return R.layout.dialog_insert_advertisement;
    }

    @Override
    public void initView(View view, Bundle bundle) {
        getDialog().getWindow().setGravity(Gravity.CENTER);
        getDialog().setCancelable(false);
        getDialog().setCanceledOnTouchOutside(false);
        getDialog().setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    return true;
                }
                return false;
            }
        });
    }

    @OnClick({R.id.insert_close_iv,R.id.insert_iv})
    public void onClick(View view){
        switch (view.getId()){
            case R.id.insert_close_iv:
                if (mClickListener!=null){
                    mClickListener.onClick(0);
                }
                exit();
                break;
            case R.id.insert_iv:
                if (mClickListener!=null){
                    mClickListener.onClick(1);
                }
               exit();
        }
    }
    public void setClickListener(AlertDialog.OnClickListener clickListener) {
        this.mClickListener = clickListener;
    }

    @Override
    public ImageView getImageView() {
        return insertIv;
    }

    public interface OnClickListener {
        /**
         * 按钮点击时间处理
         * @param position 0左边按钮点击、1右边按钮点击
         */
        void onClick(int position);
    }

    @Override
    public void initPresenter() {
        mPresenter.initPresenter(this);
    }
}
